<template>
  <view>
    <u-navbar :is-back="false" :background="background" title-color="#ffffff" title="审核列表">
      <view slot="right" class="u-flex u-m-r-30">
        <u-image
          @click="showSearchPopup = true"
          :width="48"
          :height="48"
          src="../../static/images/search.png"
        ></u-image>
      </view>
    </u-navbar>
    <u-tabs
      :list="tabList"
      :is-scroll="false"
      :show-bar="true"
      :bold="true"
      :current="tabIndex"
      active-color="#F19F41"
      @change="onTabChange"
    ></u-tabs>

    <view class="list-wrapper">
      <view class="list-item" v-for="(item, index) in reviewList" :key="index">
        <view class="u-flex u-row-between">
          <view class="u-flex">
            <u-image :width="48" :height="48" :src="item.Url"></u-image>
            <text class="module_name u-m-l-10">{{ item.ObjectName }}</text>
          </view>

          <text v-if="![21, 22, 23, 24].includes(item.ObjectId)" class="time">
            {{ (item.Created * 1000) | date('yyyy-mm-dd hh:MM:ss') }}
          </text>
          <view v-if="[21, 22, 23, 24].includes(item.ObjectId)">
            {{ parseJsonStr(item, 'WaysType') }}
            <text class=" u-m-l-10 " v-if="item.ApplyManagerName">| {{ item.ApplyManagerName }}</text>
          </view>
        </view>
        <view class="u-flex u-row-between u-m-t-10">
          <text v-if="![21, 22, 23, 24].includes(item.ObjectId)" class="name grey">{{ item.DealerName }}</text>
          <view v-if="[21, 22, 23, 24].includes(item.ObjectId)" class=" u-flex-col ">
            <text class="name grey">{{ item.DealerName }}</text>
            <text>{{ parseJsonStr(item, 'Year') }}{{ parseJsonStr(item, 'QuarterName') }}</text>
            <text style="color: #F19D38">{{ parseJsonStr(item, 'MoneyType') }}</text>
          </view>
          <text class="state" :style="{ color: item.FontColor }">{{ getStateText(item) }}</text>
        </view>

        <view v-if="![21, 22, 23, 24].includes(item.ObjectId)" class="btn-group u-m-t-20 u-text-right">
          <!-- <u-button v-if="item.ApplyManagerId = vuex_user.ManagerId" type="warning" size="medium" plain :custom-style="btnStyle" @tap="toApplyPage(item)" shape="circle">编辑</u-button> -->

          <u-button
            v-if="item.ObjectId != 29"
            type="warning"
            size="medium"
            plain
            :custom-style="btnStyle"
            @tap="toDetailPage(item)"
            shape="circle"
          >
            查看
          </u-button>

          <u-button
            class="u-m-l-30"
            type="warning"
            size="medium"
            plain
            :custom-style="btnStyle"
            @tap="toProgressPage(item)"
            shape="circle"
          >
            进度
          </u-button>

          <u-button
            v-if="item.IsAuditEnd != 1 && item.IsShowAuditBtn > 0"
            @tap="toReviewPage(item)"
            class="u-m-l-30"
            size="medium"
            type="warning"
            shape="circle"
            :custom-style="btnStyle"
          >
            审核
          </u-button>

          <u-button
            v-if="showAcceptanceBtn(item)"
            @tap="toAcceptancePage(item)"
            class="u-m-l-30"
            size="medium"
            type="warning"
            shape="circle"
            :custom-style="btnStyle"
          >
            验收
          </u-button>

          <u-button
            @tap="revoke(item)"
            plain
            v-if="showRevokeBtn(item)"
            class="u-m-l-30"
            size="medium"
            type="error"
            shape="circle"
            :custom-style="btnStyle"
          >
            撤单
          </u-button>
        </view>

        <view v-else class="btn-group u-m-t-20 u-text-right">
          <u-button
            type="warning"
            size="medium"
            plain
            :custom-style="btnStyle"
            @tap="toCostsDetailPage(item)"
            shape="circle"
          >
            详情
          </u-button>

          <u-button
            v-if="[22, 23, 24].includes(item.ObjectId)"
            class="u-m-l-30"
            type="warning"
            size="medium"
            plain
            :custom-style="btnStyle"
            @tap="toProgressPage(item)"
            shape="circle"
          >
            进度
          </u-button>

          <u-button
            v-if="showCostsReviewBtn(item)"
            class="u-m-l-30"
            type="warning"
            size="medium"
            :custom-style="btnStyle"
            @tap="toCostsReviewPage(item)"
            shape="circle"
          >
            审核
          </u-button>
        </view>
      </view>

      <u-loadmore :status="status" />
    </view>

    <u-tabbar :list="vuex_tabbar" @change="onTabbarChange" active-color="#ff7624"></u-tabbar>
    <view class="safe-area-inset-bottom"></view>

    <u-popup
      v-model="showSearchPopup"
      mode="right"
      :popup="false"
      :mask="true"
      :closeable="true"
      :safe-area-inset-bottom="true"
      close-icon-color="#ffffff"
      :z-index="999"
      :maskCloseAble="true"
      width="80%"
      @close="showSearchPopup = false"
    >
      <view class="">
        <view style="padding: 20rpx 30rpx;">
          <review-search-form @change="onSearchChange" v-model="searchParams" />
        </view>
      </view>
    </u-popup>

    <u-modal v-model="showReviewModal" :show-cancel-button="false" :show-confirm-button="false">
      <view style="padding: 24rpx;">
        <u-input v-model="activeLevelForm.AuditRemark" type="textarea"></u-input>

        <view class="u-flex">
          <u-button @click="handleReject">审核驳回</u-button>
          <u-button @click="handleSuccess" type="primary" style="background-color: #F19F41; color: #fff">
            审核通过
          </u-button>
        </view>
      </view>
    </u-modal>
  </view>
</template>

<script>
export default {
  data() {
    return {
      background: {
        backgroundColor: '#F19F41'
      },
      btnStyle: {
        height: '50rpx',
        color: '#ffffff',
        padding: '0 30rpx'
      },
      functionList: [],
      IsFirst: true,
      reviewPage: {
        Items: [],
        PageCount: 0,
        PageIndex: 0,
        PageSize: 10,
        TotalCount: 0
      },
      reviewList: [],

      searchParams: {
        TemId: null,
        TypeName: '',
        DealerName: '',
        StateName: ''
      },
      status: 'loadmore',

      ReviewList: [],
      level: 3,
      parentId: '',
      tabList: [
        {
          name: '待审核',
          value: '待审核'
        },
        {
          name: '已审核',
          value: '已审核'
        },
        {
          name: '全部',
          value: ''
        },
        {
          name: '已驳回',
          value: '已驳回'
        }
      ],
      tabIndex: 0,

      showSearchPopup: false,

      showReviewModal: false,

      AcceptancePermissionsCount: 0,
      AgreementComesBackPermissionsCount: 0,

      activeLevelForm: {
        ObjectId: '',
        AuditState: '',
        ManagerId: '',
        AuditRemark: ''
      }
    };
  },

  onLoad() {
    uni.setNavigationBarTitle({
      title: '温暖改造家'
    });
  },

  onShow() {
    this.searchParams = { ...this.searchParams, ...this.vuex_review_search_params };
    // this.searchParams.StateName = this.tabList[this.tabIndex].value;

    if (this.vuex_temId) {
      this.searchParams.TemId = this.vuex_temId;

      if (this.vuex_temId == 999 || this.vuex_temId == 1000) {
        this.tabIndex = 0;
        this.searchParams.StateName = this.tabList[this.tabIndex].value;
      }
    }

    this.reviewPage.PageIndex = 0;
    this.getData(true);
  },

  // 触底事件
  onReachBottom() {
    if (this.reviewPage.PageIndex + 1 >= this.reviewPage.PageCount) return;
    this.status = 'loading';
    this.reviewPage.PageIndex = this.reviewPage.PageIndex + 1;
    this.getData();
  },

  methods: {
    showCostsReviewBtn(item) {
      if (item.ObjectId == 21) {
        return item.IsShowAuditBtn > 0;
      } else {
        if (item.NextManagerId == this.vuex_user.ManagerId) {
          if (item.IsShowAuditBtn > 0) {
            return true;
          }
        }
        return false;
      }
    },

    toCostsDetailPage(item) {
      if (item.ObjectId == 21) {
        this.$u.route({
          url: '/pages/marketCosts/sales/predictionReviewList?showReview=0' + item.AuditRemark
        });
        return false;
      } else {
        this.$u.route({
          url: '/pages/marketCosts/sales/detail',
          params: {
            DetailId: item.Id,
            Id: item.VId
          }
        });
      }
    },

    toCostsReviewPage(item) {
      if (item.ObjectId == 21) {
        this.$u.route({
          url: '/pages/marketCosts/sales/predictionReviewList?' + item.AuditRemark
        });
      } else {
        // 执行22 .  超标23   核销.24
        if (item.ObjectId == 22 || item.ObjectId == 23) {
          this.$u.route({
            url: '/pages/marketCosts/sales/applyExecute',
            params: {
              DetailId: item.Id,
              Id: item.VId,
              type: 'review'
            }
          });
          return false;
        }

        if (item.ObjectId == 24) {
          this.$u.route({
            url: '/pages/marketCosts/sales/applyCheck',
            params: {
              DetailId: item.Id,
              Id: item.VId,
              type: 'review'
            }
          });

          return false;
        }

        this.$u.route({
          url: '/pages/marketCosts/sales/predictionReview',
          params: {
            DetailId: item.Id,
            Id: item.VId
          }
        });
      }
    },

    parseJsonStr(item, key) {
      let jsonObj = JSON.parse(item.ShowJson.replaceAll('\\', ''));

      if (jsonObj) {
        return jsonObj[key];
      }

      return '';
    },

    showRevokeBtn(item) {
      if (
        (item.AuditManagerId == item.ApplyManagerId || item.AuditManagerId == 0) &&
        (item.ObjectId != 16 && item.Object != 17) &&
        item.ApplyManagerId == this.vuex_user.ManagerId
      ) {
        return true;
      }
      return false;
    },

    showAcceptanceBtn(item) {
      // 模板样机4, 门店奖牌8 活动设计18 动力金12 渠道补贴13
      if (item.ObjectId == 4) {
        // 模块样机验收按钮显示判断
        if ((item.State == 8 || item.State == 4 || (item.State == 99 && item.IsAuditEnd == 1)) && item.AA_IsEnd == -1) {
          return true;
        }
      } else if (item.ObjectId == 8 || item.ObjectId == 6) {
        // 奖牌验收按钮显示判断
        // 户外套装验收  || item.ObjectId == 6
        if (item.State == 8 && item.AA_IsEnd == -1) {
          return true;
        }
      } else if (
        (item.ObjectId == 18 && item.ApplyForType == 3) ||
        item.ObjectId == 10 ||
        item.ObjectId == 19 ||
        item.ObjectId == 25
      ) {
        if (this.AcceptancePermissionsCount > 0) {
          // 活动设计验收按钮显示判断
          if (
            ((item.State == 99 && item.IsAuditEnd == 1) || item.State == 8) &&
            item.AA_IsEnd == -1 &&
            item.PhotoCount > 0
          ) {
            return true;
          }
        }
      } else if (item.ObjectId == 13) {
        if (this.AgreementComesBackPermissionsCount > 0) {
          //渠道补贴验收按钮显示判断
          if ((item.State == 6 || (item.State == 99 && item.IsAuditEnd == 1)) && item.AA_IsEnd == -1) {
            // 验收按钮显示
            return true;
          }
        }
      } else if (item.ObjectId == 12) {
        if (this.AgreementComesBackPermissionsCount > 0) {
          //动力金验收按钮显示判断
          if ((item.State == 6 || (item.State == 99 && item.IsAuditEnd == 1)) && item.AA_IsEnd == -1) {
            //验收按钮显示
            return true;
          }
        }
      } else {
        return false;
      }
    },

    // 从审核页面点击tabbar跳转至其他页面时清空temId
    onTabbarChange(e) {
      this.$u.vuex('vuex_temId', '');
    },

    onTabChange(index) {
      this.tabIndex = index;
      this.searchParams.StateName = this.tabList[index].value;
      this.reviewPage.PageIndex = 0;
      this.getData(true);
    },

    getStateText(item) {
      // 1渠道调整、2信息维护、5模块样机验收、9奖牌验收、11活动设计验收、14动力金协议、15渠道补贴协议、12动力金审核、13渠道补贴审核
      if ([1, 2, 5, 9, 11, 12, 13, 14, 15].includes(item.ObjectId)) {
        if (item.State == 1) {
          return '待审核';
        } else if ((item.State == 99 && item.IsAuditEnd != 1) || (item.State == 2 || item.State == 4)) {
          return '审核中';
        } else if (item.State == 3 || item.State == 5 || item.State == 7 || item.State == 101) {
          return '审核驳回';
        } else if ((item.State == 99 && item.IsAuditEnd == 1) || item.State == 6) {
          return '审核通过';
        } else if (!item.State) {
          if (item.ObjectId == 2) {
            return '待维护';
          }
          return '未申请';
        }
      }

      // 4模板样机审核, 6户外套装审核 8奖牌审核
      if ([4, 6, 8].includes(item.ObjectId)) {
        if (item.State == 1) {
          return '待审核';
        } else if ((item.State == 99 && item.IsAuditEnd != 1) || (item.State == 2 || item.State == 6)) {
          return '审核中';
        } else if (item.State == 3 || item.State == 5 || item.State == 7 || item.State == 101) {
          return '审核驳回';
        } else if ((item.State == 99 && item.IsAuditEnd == 1) || item.State == 4) {
          return '审核通过';
        } else if (!item.State) {
          return '未申请';
        } else if (item.State == 8) {
          return '已发货';
        } else if (item.State == 9) {
          return '结案';
        } else if (item.State == 10) {
          return '验收中';
        } else if (item.State == 11) {
          return '部分发货';
        }
        return '';
      }

      // 10 设计审核
      if (item.ObjectId == 10) {
        if (item.State == 1) {
          return '待审核';
        } else if ((item.State == 99 && item.IsAuditEnd != 1) || (item.State == 4 || item.State == 6)) {
          return '审核中';
        } else if (item.State == 5 || item.State == 7 || item.State == 9 || item.State == 10) {
          return '审核驳回';
        } else if ((item.State == 99 && item.IsAuditEnd == 1) || item.State == 8) {
          return '审核通过';
        } else if (!item.State) {
          return '未申请';
        }
        return '';
      }

      return item.StateName;
    },

    onSearchChange(e) {
      console.log('on search change:', e);
      this.$u.vuex('vuex_review_search_params', e);

      if (e.TemId) {
        this.$u.vuex('vuex_temId', e.TemId);
      } else {
        this.$u.vuex('vuex_temId', '');
      }

      this.showSearchPopup = false;
      this.reviewPage.PageIndex = 0;
      this.searchParams.StateName = this.tabList[this.tabIndex].value;
      this.getData(true);
    },

    toProgressPage(item) {
      this.$u.route({
        url: '/pages/review/progress',
        params: {
          id: item.Id,
          ObjectId: item.ObjectId
        }
      });
    },

    toAcceptancePage(item) {
      // 模板样机验收
      if (item.ObjectId == 4) {
        this.$u.route({
          url: '/pages/apply/module/acceptance',
          params: {
            DealerId: item.DealerId,
            ModultPrototypeAuditId: item.Id
          }
        });
        return false;
      }

      // 户外验收
      if (item.ObjectId == 6) {
        this.$u.route({
          url: '/pages/apply/outdoor/acceptance',
          params: {
            DealerId: item.DealerId,
            ModultPrototypeAuditId: item.Id
          }
        });
      }

      // 奖牌验收
      if (item.ObjectId == 8) {
        this.$u.route({
          url: '/pages/apply/medals/acceptance',
          params: {
            DealerId: item.DealerId,
            ModultPrototypeAuditId: item.Id
          }
        });
        return false;
      }

      // 设计验收
      if (item.ObjectId == 10 || item.ObjectId == 18 || item.ObjectId == 19 || item.ObjectId == 25) {
        if (item.ApplyForType == 6 || item.ApplyForType == 7) {
          this.$u.route({
            url: '/pages/review/agreement/flagshipStoreDesign',
            params: {
              ApplyId: item.Id,
              DealerId: item.DealerId,
              ApplyForType: item.ApplyForType
            }
          });

          return false;
        }

        this.$u.route({
          url: '/pages/apply/design/acceptance',
          params: {
            ApplyId: item.Id,
            DealerId: item.DealerId,
            ApplyForType: item.ApplyForType
          }
        });
        return false;
      }

      // 动力金验收
      if (item.ObjectId == 12) {
        this.$u.route({
          url: '/pages/apply/storeCosts/agreement',
          params: {
            StoreRenovationId: item.Id,
            ApplyType: 1,
            DealerId: item.DealerId
          }
        });
        return false;
      }

      //  渠道补贴验收
      if (item.ObjectId == 13) {
        this.$u.route({
          url: '/pages/apply/storeCosts/agreement',
          params: {
            StoreRenovationId: item.Id,
            ApplyType: 2,
            DealerId: item.DealerId
          }
        });
        return false;
      }
    },

    toDetailPage(item) {
      // 渠道调整详情
      if (item.ObjectId == 1) {
        if (item.ApplyForType == 1) {
          this.$u.route({
            url: '/pages/review/change/detail',
            params: {
              DealerId: item.DealerId,
              ApplayTypeId: item.ApplyForType,
              AdjustmentId: item.Id
            }
          });
          return false;
        }

        // 关停, 并转
        if (item.ApplyForType == 2 || item.ApplyForType == 3) {
          this.$u.route({
            url: '/pages/review/change/closeAndShiftReviewDetail',
            params: {
              DealerId: item.DealerId,
              ApplyForType: item.ApplyForType,
              Id: item.Id
            }
          });
          return false;
        }
      }

      // 信息维护详情
      if (item.ObjectId == 2) {
        this.$u.route({
          url: '/pages/review/information/detail',
          params: {
            InfoId: item.Id
          }
        });
        return false;
      }

      // 门店照片审核详情
      if (item.ObjectId == 3) {
        this.$u.route({
          url: '/pages/review/information/storePhoto/detail',
          params: {
            InfoId: item.Id
          }
        });
        return false;
      }

      // 模板样机审核详情
      if (item.ObjectId == 4) {
        this.$u.route({
          url: '/pages/review/module/detail',
          params: {
            DealerId: item.DealerId,
            ModultPrototypeAuditId: item.Id
          }
        });
        return false;
      }

      // 模板样机验收审核详情
      if (item.ObjectId == 5) {
        this.$u.route({
          url: '/pages/review/module/acceptanceDetail',
          params: {
            DealerId: item.DealerId,
            AcceptanceAuditId: item.Id
          }
        });
        return false;
      }

      // 户外样机审核详情
      if (item.ObjectId == 6) {
        this.$u.route({
          url: '/pages/review/outdoor/detail',
          params: {
            DealerId: item.DealerId,
            ModultPrototypeAuditId: item.Id
          }
        });
        return false;
      }

      // 户外样机验收审核详情
      if (item.ObjectId == 7) {
        this.$u.route({
          url: '/pages/review/outdoor/acceptanceDetail',
          params: {
            DealerId: item.DealerId,
            AcceptanceAuditId: item.Id
          }
        });
        return false;
      }

      // 奖牌审核详情
      if (item.ObjectId == 8) {
        this.$u.route({
          url: '/pages/review/medals/detail',
          params: {
            DealerId: item.DealerId,
            ModultPrototypeAuditId: item.Id
          }
        });
        return false;
      }

      // 奖牌验收审核详情
      if (item.ObjectId == 9) {
        this.$u.route({
          url: '/pages/review/medals/acceptanceDetail',
          params: {
            DealerId: item.DealerId,
            AcceptanceAuditId: item.Id
          }
        });
        return false;
      }

      // 设计审核详情
      if (item.ObjectId == 10) {
        if (item.ApplyForType == 6 || item.ApplyForType == 7) {
          this.$u.route({
            url: '/pages/review/design/flagshipStoreDetail',
            params: {
              Id: item.Id,
              DealerId: item.DealerId,
              ObjectType: item.ApplyForType
            }
          });

          return false;
        }

        this.$u.route({
          url: '/pages/review/design/detail',
          params: {
            ApplyId: item.Id
          }
        });
        return false;
      }

      if (item.ObjectId == 11) {
        this.$u.route({
          url: '/pages/review/design/agreementReviewDetail',
          params: {
            Id: item.Id,
            DealerId: item.DealerId
          }
        });
        return false;
      }

      // 动力金审核详细
      if (item.ObjectId == 12) {
        this.$u.route({
          url: '/pages/review/storeCosts/detail',
          params: {
            StoreRenovationId: item.Id,
            ApplyType: 1
          }
        });
        return false;
      }

      if (item.ObjectId == 14) {
        this.$u.route({
          url: '/pages/review/agreement/store',
          params: {
            AgreementAcceptanceId: item.Id,
            ApplyType: 2
          }
        });
        return false;
      }

      // 渠道补贴审核详细
      if (item.ObjectId == 13) {
        this.$u.route({
          url: '/pages/review/storeCosts/detail',
          params: {
            StoreRenovationId: item.Id,
            ApplyType: 2
          }
        });
        return false;
      }

      if (item.ObjectId == 15) {
        this.$u.route({
          url: '/pages/review/agreement/store',
          params: {
            AgreementAcceptanceId: item.Id,
            ApplyType: 1
          }
        });
        return false;
      }

      if (item.ObjectId == 17 || item.ObjectId == 16) {
        this.$u.route({
          url: '/pages/review/order/detail',
          params: {
            OrderId: item.Id,
            OrderCode: ''
          }
        });
        return false;
      }

      if (item.ObjectId == 18 || item.ObjectId == 19 || item.ObjectId == 25) {
        this.$u.route({
          url: '/pages/review/design/detail',
          params: {
            ApplyId: item.Id,
            SelectType: 1
          }
        });
        return false;
      }

      if (item.ObjectId == 20) {
        this.$u.route({
          url: '/pages/review/change/flagshipStoreDetail',
          params: {
            Id: item.Id
          }
        });
        return false;
      }

      if (item.ObjectId == 28) {
        this.$u.route({
          url: '/pages/review/design/flagshipStoreAgreementDetail',
          params: {
            Id: item.Id,
            DealerId: item.DealerId,
            ObjectType: item.ApplyForType
          }
        });
        return false;
      }

      if (item.ObjectId == 30) {
        this.$u.route({
          url: '/pages/review/channel/register',
          params: {
            Id: item.Id,
            showApproval: false
          }
        });
        return;
      }

      if (item.ObjectId == 31) {
        this.$u.route({
          url: '/pages/review/channel/order',
          params: {
            Id: item.Id,
            type: 1
          }
        });
        return;
      }

      if (item.ObjectId == 32) {
        this.$u.route({
          url: '/pages/review/channel/order',
          params: {
            Id: item.Id,
            type: 2
          }
        });
        return;
      }
    },

    revoke(item) {
      let me = this;
      uni.showModal({
        title: '确认撤销?',
        success(res) {
          if (res.confirm) {
            me.$u.api
              .revoke({
                Type: 1,
                Id: item.Id,
                ObjectId: item.ObjectId
              })
              .then(res => {
                const { ResultCode, ResultMessage } = res;
                if (ResultCode == 1) {
                  me.$u.toast(ResultMessage);
                  me.getData(true);
                }
              });
          }
        }
      });
    },

    toReviewPage(item) {
      // 渠道调整审核
      if (item.ObjectId == 1) {
        if (item.ApplyForType == 1) {
          this.$u.route({
            url: '/pages/review/change/newStore',
            params: {
              DealerId: item.DealerId,
              ApplyForType: item.ApplyForType,
              Id: item.Id
            }
          });
        }

        // 关停, 并转
        if (item.ApplyForType == 2 || item.ApplyForType == 3) {
          this.$u.route({
            url: '/pages/review/change/closeAndShiftReview',
            params: {
              DealerId: item.DealerId,
              ApplyForType: item.ApplyForType,
              Id: item.Id
            }
          });
        }
      }

      // 信息维护审核
      if (item.ObjectId == 2) {
        this.$u.route({
          url: '/pages/review/information/review',
          params: {
            InfoId: item.Id,
            DealerId: item.DealerId
          }
        });
      }

      // 门店照片审核
      if (item.ObjectId == 3) {
        this.$u.route({
          url: '/pages/review/information/storePhoto/review',
          params: {
            InfoId: item.Id,
            DealerId: item.DealerId
          }
        });
      }

      // 模板样机审核
      if (item.ObjectId == 4) {
        this.$u.route({
          url: '/pages/review/module/review',
          params: {
            DealerId: item.DealerId,
            Id: item.Id
          }
        });
      }

      // 模板样机验收审核
      if (item.ObjectId == 5) {
        this.$u.route({
          url: '/pages/review/module/acceptanceReview',
          params: {
            DealerId: item.DealerId,
            Id: item.Id
          }
        });
      }

      // 户外样机审核
      if (item.ObjectId == 6) {
        this.$u.route({
          url: '/pages/review/outdoor/review',
          params: {
            DealerId: item.DealerId,
            Id: item.Id
          }
        });
      }

      // 户外样机验收审核
      if (item.ObjectId == 7) {
        this.$u.route({
          url: '/pages/review/outdoor/acceptanceReview',
          params: {
            DealerId: item.DealerId,
            Id: item.Id
          }
        });
      }

      // 奖牌审核
      if (item.ObjectId == 8) {
        this.$u.route({
          url: '/pages/review/medals/review',
          params: {
            DealerId: item.DealerId,
            Id: item.Id
          }
        });
      }

      // 奖牌验收审核
      if (item.ObjectId == 9) {
        this.$u.route({
          url: '/pages/review/medals/acceptanceReview',
          params: {
            DealerId: item.DealerId,
            Id: item.Id
          }
        });
      }

      // 设计审核
      if (item.ObjectId == 10) {
        if (item.ApplyForType == 6 || item.ApplyForType == 7) {
          this.$u.route({
            url: '/pages/review/design/flagshipStore',
            params: {
              Id: item.Id,
              DealerId: item.DealerId,
              ObjectType: item.ApplyForType
            }
          });

          return false;
        }

        this.$u.route({
          url: '/pages/review/design/review',
          params: {
            Id: item.Id,
            DealerId: item.DealerId
          }
        });
        return;
      }

      // 设计验收审核
      if (item.ObjectId == 11) {
        this.$u.route({
          url: '/pages/review/agreement/review',
          params: {
            Id: item.Id,
            DealerId: item.DealerId
          }
        });
      }

      // 动力金审核
      if (item.ObjectId == 12) {
        this.$u.route({
          url: '/pages/review/storeCosts/review',
          params: {
            Id: item.Id,
            DealerId: item.DealerId,
            ApplyType: 1
          }
        });
      }

      // 渠道补贴审核
      if (item.ObjectId == 13) {
        this.$u.route({
          url: '/pages/review/storeCosts/review',
          params: {
            Id: item.Id,
            DealerId: item.DealerId,
            ApplyType: 2
          }
        });
      }

      // 动力金验收审核
      if (item.ObjectId == 14) {
        this.$u.route({
          url: '/pages/review/storeCosts/agreenmentReview',
          params: {
            Id: item.Id,
            DealerId: item.DealerId,
            ApplyType: 1
          }
        });
      }

      // 渠道补贴验收审核
      if (item.ObjectId == 15) {
        this.$u.route({
          url: '/pages/review/storeCosts/agreenmentReview',
          params: {
            Id: item.Id,
            DealerId: item.DealerId,
            ApplyType: 2
          }
        });
      }

      if (item.ObjectId == 17 || item.ObjectId == 16) {
        this.$u.route({
          url: '/pages/review/order/review',
          params: {
            OrderId: item.Id
          }
        });
      }

      if (item.ObjectId == 18 || item.ObjectId == 19 || item.ObjectId == 25) {
        this.$u.route({
          url: '/pages/review/design/review',
          params: {
            Id: item.Id,
            DealerId: item.DealerId
          }
        });
      }

      if (item.ObjectId == 20) {
        this.$u.route({
          url: '/pages/review/change/flagshipStore',
          params: {
            Id: item.Id
          }
        });
        return;
      }

      if (item.ObjectId == 28) {
        this.$u.route({
          url: '/pages/review/agreement/flagshipStoreDesignAgreenmentReview',
          params: {
            Id: item.Id,
            DealerId: item.DealerId,
            ApplyForType: item.ApplyForType
          }
        });
        return;
      }

      if (item.ObjectId == 29) {
        let me = this;
        me.showReviewModal = true;
        me.activeLevelForm.ManagerId = me.vuex_user.ManagerId;
        me.activeLevelForm.ObjectId = item.Id;
        return;
      }

      if (item.ObjectId == 30) {
        this.$u.route({
          url: '/pages/review/channel/register',
          params: {
            Id: item.Id,
            showApproval: true
          }
        });
        return;
      }

      if (item.ObjectId == 31) {
        this.$u.route({
          url: '/pages/review/channel/order',
          params: {
            Id: item.Id,
            showApproval: true,
            type: 1
          }
        });
        return;
      }
      if (item.ObjectId == 32) {
        this.$u.route({
          url: '/pages/review/channel/order',
          params: {
            Id: item.Id,
            showApproval: true,
            type: 2
          }
        });
        return;
      }
    },

    getData(reload) {
      this.$u.api
        .getAuditList({
          ...this.searchParams,
          ...{
            Pageindex: this.reviewPage.PageIndex,
            Pagesize: this.reviewPage.PageSize
          }
        })
        .then(res => {
          const { AuditList, AcceptancePermissionsCount, AgreementComesBackPermissionsCount } = res;

          this.AcceptancePermissionsCount = AcceptancePermissionsCount;
          this.AgreementComesBackPermissionsCount = AgreementComesBackPermissionsCount;

          this.showSearchPopup = false;

          if (AuditList) {
            this.reviewPage = AuditList;
            if (reload) {
              this.reviewList = AuditList.Items;
            } else {
              this.reviewList.push(...AuditList.Items);
            }

            if (this.reviewPage.PageIndex + 1 >= this.reviewPage.PageCount) {
              this.status = 'nomore';
            }
          } else {
            this.reviewList = [];
            this.status = 'nomore';
          }
        });
    },

    handleReject() {
      let me = this;
      me.activeLevelForm.AuditState = 2;

      me.$u.api
        .activeLevelApproval(me.activeLevelForm)
        .then(res => {
          if (res.ResultCode === 1) {
            this.getData(true);
            uni.showToast({
              title: '操作成功'
            });
          }
        })
        .finally(() => {
          me.showReviewModal = false;
        });
    },

    handleSuccess() {
      let me = this;
      me.activeLevelForm.AuditState = 1;

      me.$u.api
        .activeLevelApproval(me.activeLevelForm)
        .then(res => {
          if (res.ResultCode === 1) {
            this.getData(true);

            uni.showToast({
              title: '操作成功'
            });
          }
        })
        .finally(() => {
          me.showReviewModal = false;
        });
    },

    toList(item) {
      this.$u.route({
        url: '/'
      });
    }
  }
};
</script>

<style>
page {
  background-color: #eceaef;
}
</style>

<style lang="scss">
.card-grid {
  margin: 0 40rpx;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-auto-rows: auto;
  gap: 30rpx 40rpx;
  margin-top: 40rpx;

  .card-item {
    background-color: #ffffff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 16rpx;
    padding: 30rpx 0;

    .label {
      margin-top: 10rpx;
    }
  }
}

.list-wrapper {
  margin: 20rpx 30rpx;

  .list-item {
    background-color: #ffffff;
    border-radius: 16rpx;
    margin-bottom: 30rpx;
    padding: 30rpx;

    .grey {
      color: #9c9c9c;
    }

    .state {
      font-size: 32rpx;
      display: inline-block;
      width: 140rpx;
    }

    .module_name {
      color: #787878;
      font-weight: bold;
      font-weight: 32rpx;
    }

    .apply-name,
    .type-name {
      margin-left: 10rpx;
      font-size: 30rpx;
      display: inline-block;
      text-align: left;
    }

    .time {
      color: #9999a2;
    }
  }
}
</style>
